package genia.controller;

import genia.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import genia.entity.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @RequestMapping("/files")
    public String files(){
        return "FileProcess";
    }

    // 用户登录
    @RequestMapping("userLogin")
    public String userlogin (@RequestParam("username") String username,
                             @RequestParam("password") String password,
                             HttpServletRequest req,
                             HttpServletResponse resp,
                             Model model) {
        System.out.println(username);
        System.out.println(password);
        boolean result = userService.userLogin(new User(null,username,password));
        System.out.println(result);
        if(result){
            // 登录成功
            req.getSession().setAttribute("user",username);
            return "FileProcess";
        }
        else{
            return "login";
        }
    }
}
